/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Libros;

/**
 *
 * @author carlosenriquez
 */

import Tablas.Libros;
import java.io.File;
import java.util.Iterator;
import org.hibernate.Session;
import org.hibernate.SessionFactory; 
import org.hibernate.cfg.Configuration;
import org.hibernate.Transaction;

public class Read {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Session session = null;
        Configuration configuration=new Configuration();
        SessionFactory sessionFactory=configuration.configure().buildSessionFactory();
        session=sessionFactory.openSession();
        Transaction transaction=session.beginTransaction();
        
        
        try {
            configuration.configure();
            session.beginTransaction();
            String HQL_QUERY= "from Libros libros";
            org.hibernate.Query query= session.createQuery(HQL_QUERY);
            System.out.println("Reading values...");
            
            for(Iterator it= query.iterate(); it.hasNext();){
                Libros lib= (Libros) it.next();
                System.out.println("-------------------");
                System.out.println("ID:" +lib.getIdLibros());
                System.out.println("TITULO: "+lib.getTitulo());
                System.out.println("-------------------");
        }
            session.getTransaction().commit();
            System.out.println("Done!");
    }
    catch(Exception e){
    System.out.println(e.getMessage());
}
    finally{
    session.flush();
    session.close();
}
    }
    
}
